import 'package:flutter/material.dart';
import 'package:lib_uikit/lib_uikit.dart';

enum GTAlertTypeV3 { info, yellow, red }

class GTAlertV3 extends StatefulWidget {
  final GTAlertTypeV3? type;
  final bool? showStartIcon;
  final bool? showCloseIcon;
  final String text;
  final String? endText;
  final bool? marqueeStyle;
  final double? lineSpace;
  final String? bottomText;
  final VoidCallback? onBottomClick;
  final VoidCallback? onCloseClick;
  final bool? hasRadius;

  const GTAlertV3(
      {super.key,
      this.type = GTAlertTypeV3.info,
      this.showStartIcon = true,
      required this.text,
      this.endText,
      this.showCloseIcon,
      this.marqueeStyle,
      this.lineSpace = 1.5,
      this.bottomText,
      this.onBottomClick,
      this.onCloseClick,
      this.hasRadius});

  @override
  State<StatefulWidget> createState() => _AlertStateV3();
}

class _AlertStateV3 extends State<GTAlertV3> {
  bool isContainerVisible = true;

  @override
  Widget build(BuildContext context) {
    GTAlertTypeV3 type = widget.type ?? GTAlertTypeV3.info;
    Color backgroundColor, iconColor;

    switch (type) {
      case GTAlertTypeV3.info:
        backgroundColor = GTColorsV3.cmpt7.color;
        iconColor = GTColorsV3.icon5.color;
        break;
      case GTAlertTypeV3.yellow:
        backgroundColor = GTColorsV3.cmpt3.color;
        iconColor = GTColorsV3.color2.color;
        break;
      case GTAlertTypeV3.red:
        backgroundColor = GTColorsV3.cmpt4.color;
        iconColor = GTColorsV3.funct3.color;
        break;
    }

    return Visibility(
        visible: isContainerVisible,
        child: Container(
          padding: const EdgeInsets.all(12),
          decoration: BoxDecoration(
              color: backgroundColor, borderRadius: BorderRadius.circular((widget.hasRadius ?? false) ? 6 : 0)),
          constraints: const BoxConstraints(minHeight: 40),
          child: Column(
            children: [
              Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  if (widget.showStartIcon ?? true) ...[
                    Padding(
                      padding: const EdgeInsets.only(top: 3),
                      child: Stack(
                        alignment: Alignment.center,
                        children: [
                          Container(
                            width: 8,
                            height: 8,
                            color: GTColorsV3.icon6.color,
                          ),
                          Icon(
                            GTIconFont.ea00,
                            color: iconColor,
                            size: 12,
                          ),
                        ],
                      ),
                    ),
                    const SizedBox(
                      width: 8,
                    )
                  ],
                  Expanded(
                    child: Text(
                      widget.text,
                      style: gtTextStyleW400(fontSize: 12, color: GTColorsV3.text1.color)
                          .copyWith(height: widget.lineSpace),
                    ),
                  ),
                  if (widget.endText != null) ...[
                    const SizedBox(
                      width: 8,
                    ),
                    Text(
                      widget.endText ?? "",
                      style: gtTextStyleW600(fontSize: 12, color: GTColorsV3.text5.color),
                    ),
                  ],
                  if (widget.showCloseIcon ?? false) ...[
                    SizedBox(
                      width: widget.endText != null ? 12 : 8,
                    ),
                    GestureDetector(
                      onTap: () {
                        setState(() {
                          isContainerVisible = false;
                          widget.onCloseClick?.call();
                        });
                      },
                      child: Icon(
                        GTIconFont.e95d,
                        size: 12,
                        color: GTColorsV3.icon3.color,
                      ),
                    ),
                  ]
                ],
              ),
              if ((widget.bottomText ?? "").isNotEmpty) ...[
                const SizedBox(
                  height: 8,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: [
                    GestureDetector(
                      onTap: () {
                        widget.onBottomClick?.call();
                      },
                      child: Text(
                        widget.bottomText ?? "",
                        style: gtTextStyleW600(fontSize: 12, color: GTColorsV3.text5.color),
                      ),
                    ),
                  ],
                ),
              ],
            ],
          ),
        ));
  }
}
